VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmImpresora 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Seleccionar Impresora"
   ClientHeight    =   4710
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6630
   ControlBox      =   0   'False
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4710
   ScaleWidth      =   6630
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdImp 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Caption         =   "&Imprimir"
      Height          =   390
      Left            =   3840
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   0
      ToolTipText     =   "Imprimir (F5)"
      Top             =   4200
      Width           =   1140
   End
   Begin VB.CommandButton cmdCancel 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   390
      Left            =   5040
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Cancelar (Esc)"
      Top             =   4200
      Width           =   1140
   End
   Begin MSComctlLib.ListView lstImp 
      Height          =   4095
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   6615
      _ExtentX        =   11668
      _ExtentY        =   7223
      Sorted          =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      HideColumnHeaders=   -1  'True
      _Version        =   393217
      Icons           =   "imgImp"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   1
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Impresoras"
         Object.Width           =   2540
      EndProperty
   End
   Begin MSComctlLib.ImageList imgImp 
      Left            =   2880
      Top             =   3960
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   48
      ImageHeight     =   48
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   4
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmImpresora.frx":0000
            Key             =   "impresora"
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmImpresora.frx":0EDA
            Key             =   "predeterminada"
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmImpresora.frx":1DB4
            Key             =   "red"
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmImpresora.frx":2C8E
            Key             =   "red predeterminada"
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmImpresora"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public sinPuerto As Boolean

Private Sub cmdCancel_Click()

ImpresoraSeleccionada = ""
Unload Me

End Sub

Private Sub cmdImp_Click()

ImpresoraSeleccionada = ""

Dim p As Printer
If lstImp.SelectedItem.Index > 0 Then
    For Each p In Printers
        If lstImp.SelectedItem.Key = p.DeviceName Then
            If sinPuerto Then
                ImpresoraSeleccionada = p.DeviceName
            Else
                ImpresoraSeleccionada = p.DeviceName & " en " & p.Port
            End If
            Exit For
        End If
    Next
End If

GrabarINI p.DeviceName, "General", "Impresora", App.Path & "\Turnos.ini"
Set p = Nothing

Unload Me

End Sub

Private Sub Form_Load()

Centrar Me

Dim p As Printer, defecto As String, usada As String

usada = LeerCadenaINI("General", "Impresora", App.Path & "\Turnos.ini", "")
defecto = Printer.DeviceName
lstImp.ListItems.Clear
For Each p In Printers
    If usada = "" Then
        If defecto = p.DeviceName Then
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 4, 2)
            lstImp.ListItems(p.DeviceName).Selected = True
        Else
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 3, 1)
        End If
    Else
        If usada = p.DeviceName And defecto = p.DeviceName Then
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 4, 2)
            lstImp.ListItems(p.DeviceName).Selected = True
        ElseIf usada = p.DeviceName Then
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 3, 1)
            lstImp.ListItems(p.DeviceName).Selected = True
        ElseIf defecto = p.DeviceName Then
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 4, 2)
        Else
            lstImp.ListItems.Add , p.DeviceName, p.DeviceName, IIf(Left(p.DeviceName, 2) = "\\", 3, 1)
        End If
    End If
Next
Set p = Nothing

sinPuerto = False

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 27 'Escape "Salir"
        cmdCancel_Click
        
    Case 116 'F5 "Imprimir"
        cmdImp_Click
        
End Select

End Sub

Private Sub Form_Unload(Cancel As Integer)

sinPuerto = False

End Sub
